package com.yikome.shop.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.itmuch.lightsecurity.annotation.PreAuthorize;
import com.yikome.shop.entity.Present;
import com.yikome.shop.service.PresentService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/present")
public class PresentController {

	@Autowired
	private PresentService presentService;
	
	@GetMapping("/list")
	@PreAuthorize("hasAnyRoles('admin')")
	public List<Present> findPresents(){
		return presentService.findAllPresent();
	}
	
	@DeleteMapping("/{presentId}")
	@PreAuthorize("hasAnyRoles('admin')")
	public Boolean deletePresents(@PathVariable("presentId") Long presentId){
		
		presentService.deletePresent(presentId);
		
		return Boolean.TRUE;
	}
	
	@PostMapping
	@PreAuthorize("hasAnyRoles('admin')")
	public Present savePresents(@RequestBody Present present){
		
		return presentService.presistPresent(present);
		
	}
}
